package com.wlc.base.array;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 数组
 * @date 2021-07-18 09:12
 */
public class ArrayDemo05 {

    public void method01() {

        // 定义一个数组；
        int[] b;
        // 声明一个数组,长度是10
        b = new int[10];
        // 为数组进行赋值
        b[1] = 0;
        b[2] = 4;
        b[3] = 4;
        b[4] = 5;
        System.out.println(b[4]);
    }

    /**
     * 声明数组和赋值同时进行
     */
    public void method02() {
        // 声明数组的时候进行赋值, 省略 new int[]
        int[] a = {12, 33, 45, 556};
        System.out.println("a[1] = " + a[1]);
        // 声明数组的时候进行赋值， 带有 new int[]

        int[] b = new int[]{3, 4, 5, 667};
        System.out.println("b[0] = " + b[0]);

    }

    public void method03() {
        int[] a = {0, 1, 2, 3, 4};
        // 0,1,2,3,4
        // 0,4
        // 1,3
        // 4
        int[] b = new int[5];
        for (int i = 0; i < a.length; i++) {
            b[i] = a[a.length-1-i];
        }

        for (int i : b) {
            System.out.println(i);
        }

        System.out.println();
        int[] ints = reverse2(a);
        for (int anInt : ints) {
            System.out.println(anInt);
        }

    }
    public int[] reverse2(int[] array){
        for(int i=0;i<array.length/2;i++){
            int temp = array[i];
            array[i] = array[array.length-1-i];
            array[array.length-1-i] = temp;
        }
        return array;
    }

    public static void main(String[] args) {
        new ArrayDemo05().method03();
    }
}
